package com.lehecai.core.api.lottery;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.lottery.MatchStyleType;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 北单、竞彩赛程样式设置
 * @author He Wang
 */
public class MatchStyleSetting implements Serializable{
	private static final long serialVersionUID = 6039517163465939173L;

	public static final String QUERY_MATCH_NAME = "match_name";
	public static final String QUERY_MATCH_TYPE = "type";
	public static final String QUERY_MATCH_STATUS = "status";

	public static final String SET_MATCH_NAME = "match_name";
	public static final String SET_MATCH_TYPE = "type";
	public static final String SET_MATCH_STATUS = "status";
	public static final String SET_COLOR = "color";
	public static final String SET_IMG_SRC = "img_src";

	private MatchStyleType type;                //类型，竞彩、北单
	private String matchName;                   //赛事名称
	private YesNoStatus status;                 //状态
	private String color;                       //颜色
	private String imgSrc;                      //icon路径

	public static MatchStyleSetting convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		MatchStyleSetting matchStyleSetting = new MatchStyleSetting();

		matchStyleSetting.setMatchName(object.getString("match_name"));
		matchStyleSetting.setColor(object.getString("color"));
		matchStyleSetting.setStatus(YesNoStatus.getItem(object.getInt("status")));
		matchStyleSetting.setImgSrc(object.getString("img_src"));
		matchStyleSetting.setType(MatchStyleType.getItem(object.getInt("type")));

		return matchStyleSetting;
	}

	public static List<MatchStyleSetting> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<MatchStyleSetting> list = new ArrayList<MatchStyleSetting>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public MatchStyleType getType() {
		return type;
	}

	public void setType(MatchStyleType type) {
		this.type = type;
	}

	public String getMatchName() {
		return matchName;
	}

	public void setMatchName(String matchName) {
		this.matchName = matchName;
	}

	public YesNoStatus getStatus() {
		return status;
	}

	public void setStatus(YesNoStatus status) {
		this.status = status;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public String getImgSrc() {
		return imgSrc;
	}

	public void setImgSrc(String imgSrc) {
		this.imgSrc = imgSrc;
	}
}
